// pages/myOrder/myOrder.js
var sliderWidth = 96; // 需要设置slider的宽度，用于计算中间位置
var app = getApp();
Page({
    data: {
        tabs: ["全部订单", "等待接单", "已完成", "已取消", "待评价"],
        activeIndex: "0",
        sliderOffset: 0,
        sliderLeft: 0,
        index: 0,
        uid: null,
        temp: [],
        height: ""
    },
    onLoad: function (options) {
        var that = this;
        // console.log(options.uid)
        that.setData({
            uid: options.uid
        })
        this.setData({
            sliderOffset: options.index * 75,
            activeIndex: options.index
        })
        wx.getSystemInfo({
            success: function (res) {
                console.log(res)
                that.setData({
                    sliderLeft: (res.windowWidth / that.data.tabs.length - sliderWidth) / 2,
                    height: res.windowHeight - 50 + 'px'
                });
            }
        });
        renovate(that)
    },
    tabClick: function (e) {
        this.setData({
            sliderOffset: e.currentTarget.offsetLeft,
            activeIndex: e.currentTarget.id
        });
    },
    callToStore: function () {
        wx.makePhoneCall({
            phoneNumber: '18710408624'
        })
    },

    abolish: function (e) {
        var that = this
        // console.log(e.currentTarget.dataset.oid)
        wx.request({
            url: 'http://1.aiym.applinzi.com/aiyouwai.php',
            data: {
                type: "cancelTheOrder",
                paras: {
                    oid: e.currentTarget.dataset.oid
                }
            },
            method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
            header: { "Content-Type": "application/json" }, // 设置请求的 header
            success: function (res) {
                // success
                renovate(that)
            }
        })
    },
    urlLinkTo: function (){
        wx.navigateTo({
          url: '../server/server?ID=0'
        })
    },
    // 添加点击函数使跳转评价页面
    shareOrder:function(e){
        console.log(e)
wx.navigateTo({
  url: '../comment/comment?oid='+e.currentTarget.dataset.oid+"&uid="+e.currentTarget.dataset.uid+"&acceptshop="+e.currentTarget.dataset.acceptshop+"&image="+e.currentTarget.dataset.img,
  
})
    }
})
// 封装函数方便加载与点击取消订单的重复请求
function renovate(that) {
    wx.request({
        url: 'http://1.aiym.applinzi.com/aiyouwai.php',
        data: {
            type: "getUserOrder",
            paras: {
                uid: that.data.uid
            }
        },
        method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
        header: { "Content-Type": "application/json" }, // 设置请求的 header
        success: function (res) {
            // success
            console.log(res)
            that.setData({
                temp: res.data
            })
        }
    })
}
